{$CLEO .cs}
{$USE CLEO+}
{$USE ini}

0000: NOP

script_name "DeathMod"

// by ArtemQa146

repeat
wait 0
04ED: load_animation  "Death Anims"
until 04EE:   animation "Death Anims" loaded

const
    Damager_1 = 31@
    Type_1 = 30@
    Bone_1 = 29@
    Intensity_1 = 28@
    find_ped = 27@
    Anim_F = 26@
    Anim_HF = 25@
    Anim_B = 24@
    Anim_HB = 23@
    Anim_SF = 22@
    Anim_H = 21@
    Anim_L = 20@
    Anim_R = 19@
    Char_damage = 18@
    Player_anim = 17@
end

0AF0: Anim_F = read_int_from_ini_file "cleo\DeathMod.ini" section "Settings" key "Animation F"
0AF0: Anim_HF = read_int_from_ini_file "cleo\DeathMod.ini" section "Settings" key "Animation HF"
0AF0: Anim_B = read_int_from_ini_file "cleo\DeathMod.ini" section "Settings" key "Animation B"
0AF0: Anim_HB = read_int_from_ini_file "cleo\DeathMod.ini" section "Settings" key "Animation HB"
0AF0: Anim_SF = read_int_from_ini_file "cleo\DeathMod.ini" section "Settings" key "Animation SF"
0AF0: Anim_H = read_int_from_ini_file "cleo\DeathMod.ini" section "Settings" key "Animation H"
0AF0: Anim_L = read_int_from_ini_file "cleo\DeathMod.ini" section "Settings" key "Animation L"
0AF0: Anim_R = read_int_from_ini_file "cleo\DeathMod.ini" section "Settings" key "Animation R"
0AF0: Player_anim = read_int_from_ini_file "cleo\DeathMod.ini" section "Settings" key "Player Death Animations"

Anim_F += 1
Anim_HF += 1
Anim_B += 1
Anim_HB += 1
Anim_SF += 1
Anim_H += 1
Anim_L += 1
Anim_R += 1

set_script_event_char_damage 1 label @DeathMod_Damage var_char Char_damage

while true
wait 0
    if
        player.Defined($PLAYER_CHAR)
    then
        find_ped = 0
        while 0EA7: get_any_char_no_save_recursive find_ped progress_to find_ped char_to 0@
        
        if 003B:   0@ == $PLAYER_ACTOR  // (int)
        then continue
        end
        
        0226: 1@ = actor $PLAYER_ACTOR health
            if
                1@ < 1
            then
                if
                    Player_anim == 1
                then
                    Actor.EmulateFromPlayer(0@, 0)
                end
            end

                
                0ECE: get_time_char_is_dead 0@ store_to 1@
                0226: 2@ = actor 0@ health // because get_time_char_is_dead sometimes sees the living as dead, often when you get knocked down by a car
                    if and
                        2@ < 1
                        1@ < 300 // a fresh body
                        not 1@ == -1
                    then
                    
                    if
                        not $ACTIVE_INTERIOR == 0
                    then
                        if
                            Damager_1 == 0
                        then
                            continue
                        end
                    end

                        //     

                        if
                            Actor.Animation(0@) == "KO_SKID_FRONT"
                        then
                            if and
                                003B:   Char_damage == 0@  // (int)
                                Intensity_1 > 200.0
                            then
                                0792: disembark_instantly_actor 0@
                                0209: 1@ = random_int_in_ranges 1 Anim_HF
                                0AD3: 2@v = string_format "HF%d" 1@
                                0829: actor 0@ perform_animation 2@v IFP_file "Death Anims" 5.0 time -1 and_dies
                                wait 0
                                continue
                            else
                                0792: disembark_instantly_actor 0@
                                0209: 1@ = random_int_in_ranges 1 Anim_F
                                0AD3: 2@v = string_format "F%d" 1@
                                0829: actor 0@ perform_animation 2@v IFP_file "Death Anims" 4.0 time -1 and_dies
                                wait 0
                                continue
                            end
                        end


                        if
                            Actor.Animation(0@) == "KO_SKID_BACK"
                        then
                            if and
                                003B:   Char_damage == 0@  // (int)
                                Intensity_1 > 200.0
                            then
                                0792: disembark_instantly_actor 0@
                                0209: 1@ = random_int_in_ranges 1 Anim_HB
                                0AD3: 2@v = string_format "HB%d" 1@
                                0829: actor 0@ perform_animation 2@v IFP_file "Death Anims" 4.0 time -1 and_dies
                                wait 0
                                continue
                            else
                                0792: disembark_instantly_actor 0@
                                0209: 1@ = random_int_in_ranges 1 Anim_B
                                0AD3: 2@v = string_format "B%d" 1@
                                0829: actor 0@ perform_animation 2@v IFP_file "Death Anims" 4.0 time -1 and_dies
                                wait 0
                                continue
                            end
                        end
  
                        if
                            Actor.Animation(0@) == "KO_SPIN_L"
                        then
                            0792: disembark_instantly_actor 0@
                            0209: 1@ = random_int_in_ranges 1 Anim_L
                            0AD3: 2@v = string_format "L%d" 1@
                            0829: actor 0@ perform_animation 2@v IFP_file "Death Anims" 4.0 time -1 and_dies
                            wait 0
                            continue
                        end
      
                        if
                            Actor.Animation(0@) == "KO_SPIN_R"
                        then
                            0792: disembark_instantly_actor 0@
                            0209: 1@ = random_int_in_ranges 1 Anim_R
                            0AD3: 2@v = string_format "R%d" 1@
                            0829: actor 0@ perform_animation 2@v IFP_file "Death Anims" 4.0 time -1 and_dies
                            wait 0
                            continue
                        end
        

                        if and
                            Actor.Animation(0@) == "KO_SHOT_FRONT"
                            Bone_1 == 9
                            Intensity_1 < 30.0
                            003B:   Char_damage == 0@  // (int)
                        then
                            0792: disembark_instantly_actor 0@
                            0209: 1@ = random_int_in_ranges 1 Anim_H
                            0AD3: 2@v = string_format "H%d" 1@
                            0829: actor 0@ perform_animation 2@v IFP_file "Death Anims" 4.0 time -1 and_dies
                            wait 0
                            continue
                        end


                        if
                            Actor.Animation(0@) == "KO_SHOT_FRONT"
                        then
                            0792: disembark_instantly_actor 0@
                            0209: 1@ = random_int_in_ranges 1 Anim_SF
                            0AD3: 2@v = string_format "SF%d" 1@
                            0829: actor 0@ perform_animation 2@v IFP_file "Death Anims" 4.0 time -1 and_dies
                            wait 0
                            continue
                        end


            end
        end
    end
end

:DeathMod_Damage
get_char_damage_last_frame Char_damage damager Damager_1 type Type_1 part Bone_1 intensity Intensity_1   // type = gun int, part = bone char int, intensity = damage float
return_script_event

            